package com.example.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.alibaba.fastjson.JSONObject;
import com.example.demo.services.WeChatLogin;

/**
 * @author Buer
 * @update 2021/4/25/02510:05
 */
@RestController
public class WeChatControl {
    @Autowired
    private WeChatLogin weChatLogin;

    /** 登录验证账号、密码，JSON包 */
    @PostMapping(value = "/wxLogin/first", produces = "application/json;charset=UTF-8")
    public Object weChatVerify(@RequestBody JSONObject info) {
        // 测试信息流
        System.out.println("jsonParam = " + info.toString());
        return JSONObject.toJSON(weChatLogin.firstLogin(info));
    }

    /** 传入用户名和头像地址 */
    @PostMapping(path = "/wxLogin/image", produces = "application/json;charset=UTF-8")
    public Boolean wxLogin1(@RequestBody JSONObject info) {
        // 测试传入对象
        System.out.println(info.toString());
        return weChatLogin.setImage(info);
    }

    /** 传入token,进行二次验证 */
    @GetMapping("/wxLogin/verify")
    public Boolean wxLogin(@RequestParam(value = "token") String token) {
        return weChatLogin.isVerify(token);
    }
}
